#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <set>
#define int long long
using namespace std;

signed main()
{
    int n;
    cin >> n;
    vector<int>arr(n + 10);
    vector<int>cnt1(n + 10);
    vector<bool>st(n + 10);
    int sum = 0;
    for(int i = 1; i <= n; i ++) 
    {
        cin >> arr[i];
        cnt1[arr[i]] ++;
        if(cnt1[arr[i]] == 2) sum ++;
    }   
    int ans = 0;
    for(int i = 1; i <= n; i ++)
    {
        cnt1[arr[i]] --;
        if(cnt1[arr[i]] == 1) sum --;
        int res = cnt1[arr[i]] >= 2;
        if(st[arr[i]] == 0) ans += sum - res,st[arr[i]] = 1;
    }
    cout << ans << endl;
}